package com.rech.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.TextView;

import com.rech.adapter.adapterInterface.BaseAdapter;
import com.rech.module.AddressModule;
import com.rech.xbexpress3.R;

import java.util.List;

/**
 * Created by sunshine on 2020/9/16
 */
public class AddressAdapter extends BaseAdapter<AddressAdapter.AddressHolder> {
    private Context context;
    private List<AddressModule> data;

    public AddressAdapter(Context context, @NonNull List<AddressModule> data) {
        this.context = context;
        this.data = data;
    }


    @Override
    public AddressAdapter.AddressHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_address, parent, false);
        AddressAdapter.AddressHolder holder = new AddressAdapter.AddressHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(final AddressAdapter.AddressHolder holder, @SuppressLint("RecyclerView") final int position) {
        holder.tvName.setText(data.get(position).getDetail());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                listener.onItemClick(position);
            }
        });
    }


    @Override
    public int getItemCount() {
        return data.size();
    }

    static class AddressHolder extends RecyclerView.ViewHolder {
        TextView tvName;
        public AddressHolder(View itemView) {
            super(itemView);

            tvName = itemView.findViewById(R.id.tv_logistic_name);
        }
    }

}
